﻿using System;
using System.Data;
using System.Collections;
using CE.Database;


/// <summary>
/// Summary description for RsaCarMoreDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class RsaCarMoreDetailDB
    {
        public RsaCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(RsaCarMoreDetail rsacarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemRsa";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", rsacarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarID", rsacarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", rsacarmoredetail.ProviderCompanyId);

            _sPara.Add("@Salutation", rsacarmoredetail.Salutation);

            _sPara.Add("@Name", rsacarmoredetail.Name);
            _sPara.Add("@NRICNo", rsacarmoredetail.NRICNo);
            _sPara.Add("@Nationality", rsacarmoredetail.Nationality);
            _sPara.Add("@PostalCode", rsacarmoredetail.PostalCode);
            _sPara.Add("@UnitNo", rsacarmoredetail.UnitNo);
            _sPara.Add("@HomeNo", rsacarmoredetail.HomeNo);
            _sPara.Add("@Address", rsacarmoredetail.Address);
            _sPara.Add("@MobileNo", rsacarmoredetail.MobileNo);
            _sPara.Add("@HomePhoneNo", rsacarmoredetail.HomePhoneNo);
            _sPara.Add("@OfficePhoneNo", rsacarmoredetail.OfficePhoneNo);
            _sPara.Add("@FaxNo", rsacarmoredetail.FaxNo);
            _sPara.Add("@DriveExpYear", rsacarmoredetail.DriveExpYear);
            _sPara.Add("@DriveExpMonth", rsacarmoredetail.DriveExpMonth);
            _sPara.Add("@DrivingLicenceNo", rsacarmoredetail.DrivingLicenceNo);
            _sPara.Add("@DrivingClass", rsacarmoredetail.DrivingClass);
            _sPara.Add("@YearObtained", rsacarmoredetail.YearObtained);

            _sPara.Add("@IsNewVehicle", rsacarmoredetail.IsNewVehicle);

            _sPara.Add("@VechicleNo", rsacarmoredetail.VechicleNo);
            _sPara.Add("@EngineNo", rsacarmoredetail.EngineNo);
            _sPara.Add("@ChassisNo", rsacarmoredetail.ChassisNo);

            _sPara.Add("@VehicleTransmission", rsacarmoredetail.VehicleTransmission);
            _sPara.Add("@VehiclePropellant", rsacarmoredetail.VehiclePropellant);
            _sPara.Add("@VehicleSumInsured", rsacarmoredetail.VehicleSumInsured);
            _sPara.Add("@ClaimODAmount", rsacarmoredetail.ClaimODAmount);
            _sPara.Add("@ClaimTPPDAmount", rsacarmoredetail.ClaimTPPDAmount);
            _sPara.Add("@IsPolicyRDCOpted", rsacarmoredetail.IsPolicyRDCOpted);

            _sPara.Add("@HasHirePurchase", rsacarmoredetail.HasHirePurchase);
            _sPara.Add("@HPCompanyName", rsacarmoredetail.HPCompanyName);
            _sPara.Add("@HasDriveWestMalaysia", rsacarmoredetail.HasDriveWestMalaysia);
            _sPara.Add("@HowOften", rsacarmoredetail.HowOften);
            _sPara.Add("@Aircon", rsacarmoredetail.Aircon);
            _sPara.Add("@Radio", rsacarmoredetail.Radio);
            _sPara.Add("@SportsRims", rsacarmoredetail.SportsRims);
            _sPara.Add("@SunRoof", rsacarmoredetail.SunRoof);
            _sPara.Add("@MoonRoof", rsacarmoredetail.MoonRoof);
            _sPara.Add("@OtherAccessories", rsacarmoredetail.OtherAccessories);
            _sPara.Add("@HasVechicleModified", rsacarmoredetail.HasVechicleModified);
            _sPara.Add("@VechicleModifyReason", rsacarmoredetail.VechicleModifyReason);
            _sPara.Add("@HasCOE", rsacarmoredetail.HasCOE);
            _sPara.Add("@CarRentalExten", rsacarmoredetail.CarRentalExten);
            _sPara.Add("@NCDProtectorExten", rsacarmoredetail.NCDProtectorExten);
            _sPara.Add("@DealerWorkShopExten", rsacarmoredetail.DealerWorkShopExten);
            _sPara.Add("@SunRoofExten", rsacarmoredetail.SunRoofExten);
            _sPara.Add("@SunRoofAmount", rsacarmoredetail.SunRoofAmount);
            _sPara.Add("@MoonRoofExten", rsacarmoredetail.MoonRoofExten);
            _sPara.Add("@MoonRoofAmount", rsacarmoredetail.MoonRoofAmount);
            _sPara.Add("@OtherExtension", rsacarmoredetail.OtherExtension);
            _sPara.Add("@SocialUse", rsacarmoredetail.SocialUse);
            _sPara.Add("@HasPhysicalImpairmty", rsacarmoredetail.HasPhysicalImpairmty);
            _sPara.Add("@PhysicalImpairmtyReason", rsacarmoredetail.PhysicalImpairmtyReason);
            _sPara.Add("@HasAccidentInvolved", rsacarmoredetail.HasAccidentInvolved);
            _sPara.Add("@AccidentInvolvedReason", rsacarmoredetail.AccidentInvolvedReason);
            _sPara.Add("@HasTrafficConvicted", rsacarmoredetail.HasTrafficConvicted);
            _sPara.Add("@TrafficConvictedReason", rsacarmoredetail.TrafficConvictedReason);
            _sPara.Add("@HasInsuranceTerminated", rsacarmoredetail.HasInsuranceTerminated);
            _sPara.Add("@InsuranceTerminatedReason", rsacarmoredetail.InsuranceTerminatedReason);
            _sPara.Add("@HasDemeritPoints", rsacarmoredetail.HasDemeritPoints);
            _sPara.Add("@HasPreInsurer", rsacarmoredetail.HasPreInsurer);
            _sPara.Add("@PreInsurerName", rsacarmoredetail.PreInsurerName);
            _sPara.Add("@PreInsVechicleNo", rsacarmoredetail.PreInsVechicleNo);
            _sPara.Add("@PreInsNCD", rsacarmoredetail.PreInsNCD);
            _sPara.Add("@PreInsPolicyNo", rsacarmoredetail.PreInsPolicyNo);
            _sPara.Add("@PreInsExpiryDate", rsacarmoredetail.PreInsExpiryDate);
            _sPara.Add("@PamentType", rsacarmoredetail.PamentType);
            //_sPara.Add("@NameoftheCard", rsacarmoredetail.NameoftheCard);
            //_sPara.Add("@IssuingBankName", rsacarmoredetail.IssuingBankName);
            //_sPara.Add("@CreditCardNo", rsacarmoredetail.CreditCardNo);
            //_sPara.Add("@CardExpiryMonth", rsacarmoredetail.CardExpiryMonth);
            //_sPara.Add("@CardExpiryYear", rsacarmoredetail.CardExpiryYear);
            //_sPara.Add("@CardType", rsacarmoredetail.CardType);
            _sPara.Add("@QuoteRefNo", rsacarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", rsacarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", rsacarmoredetail.ViewedDetailId);
            _sPara.Add("@Status", rsacarmoredetail.Status);
            _sPara.Add("@CarResultId", rsacarmoredetail.CarResultId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 UpdateStatus(RsaCarMoreDetail rsacarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCISelectedItemStatusUpdateSingleItemRsa";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarID", rsacarmoredetail.CECarId);
            _sPara.Add("@CarResultId", rsacarmoredetail.CarResultId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public RsaCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            RsaCarMoreDetail _rsacarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemRsa";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _rsacarmoredetail = new RsaCarMoreDetail();
                    _rsacarmoredetail = FillDataRecord(_dt);
                }
            }
            return _rsacarmoredetail;
        }

        private RsaCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            RsaCarMoreDetail myCarMoreDetail = new RsaCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarID"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());

            myCarMoreDetail.Salutation = myDataTable.Rows[0]["Salutation"].ToString();

            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            myCarMoreDetail.NRICNo = myDataTable.Rows[0]["NRICNo"].ToString();
            myCarMoreDetail.Nationality = myDataTable.Rows[0]["Nationality"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
            myCarMoreDetail.HomeNo = myDataTable.Rows[0]["HomeNo"].ToString();
            myCarMoreDetail.Address = myDataTable.Rows[0]["Address"].ToString();
            myCarMoreDetail.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
            myCarMoreDetail.HomePhoneNo = myDataTable.Rows[0]["HomePhoneNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            myCarMoreDetail.FaxNo = myDataTable.Rows[0]["FaxNo"].ToString();
            myCarMoreDetail.DriveExpYear = Convert.ToInt32(myDataTable.Rows[0]["DriveExpYear"].ToString());
            myCarMoreDetail.DriveExpMonth = Convert.ToInt32(myDataTable.Rows[0]["DriveExpMonth"].ToString());
            myCarMoreDetail.DrivingLicenceNo = myDataTable.Rows[0]["DrivingLicenceNo"].ToString();
            myCarMoreDetail.DrivingClass = myDataTable.Rows[0]["DrivingClass"].ToString();
            myCarMoreDetail.YearObtained = Convert.ToInt32(myDataTable.Rows[0]["YearObtained"].ToString());

            myCarMoreDetail.IsNewVehicle = Convert.ToBoolean(myDataTable.Rows[0]["IsNewVehicle"].ToString());

            myCarMoreDetail.VechicleNo = myDataTable.Rows[0]["VechicleNo"].ToString();
            myCarMoreDetail.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCarMoreDetail.ChassisNo = myDataTable.Rows[0]["ChassisNo"].ToString();

            myCarMoreDetail.VehicleTransmission = myDataTable.Rows[0]["VehicleTransmission"].ToString();
            myCarMoreDetail.VehiclePropellant = myDataTable.Rows[0]["VehiclePropellant"].ToString();
            myCarMoreDetail.VehicleSumInsured = Convert.ToSingle(myDataTable.Rows[0]["VehicleSumInsured"].ToString());
            myCarMoreDetail.ClaimODAmount = Convert.ToSingle(myDataTable.Rows[0]["ClaimODAmount"].ToString());
            myCarMoreDetail.ClaimTPPDAmount = Convert.ToSingle(myDataTable.Rows[0]["ClaimTPPDAmount"].ToString());
            myCarMoreDetail.IsPolicyRDCOpted = Convert.ToBoolean(myDataTable.Rows[0]["IsPolicyRDCOpted"].ToString());

            myCarMoreDetail.HasHirePurchase = Convert.ToBoolean(myDataTable.Rows[0]["HasHirePurchase"].ToString());
            myCarMoreDetail.HPCompanyName = myDataTable.Rows[0]["HPCompanyName"].ToString();
            myCarMoreDetail.HasDriveWestMalaysia = Convert.ToBoolean(myDataTable.Rows[0]["HasDriveWestMalaysia"].ToString());
            myCarMoreDetail.HowOften = myDataTable.Rows[0]["HowOften"].ToString();
            myCarMoreDetail.Aircon = Convert.ToBoolean(myDataTable.Rows[0]["Aircon"].ToString());
            myCarMoreDetail.Radio = Convert.ToBoolean(myDataTable.Rows[0]["Radio"].ToString());
            myCarMoreDetail.SportsRims = Convert.ToBoolean(myDataTable.Rows[0]["SportsRims"].ToString());
            myCarMoreDetail.SunRoof = Convert.ToBoolean(myDataTable.Rows[0]["SunRoof"].ToString());
            myCarMoreDetail.MoonRoof = Convert.ToBoolean(myDataTable.Rows[0]["MoonRoof"].ToString());
            myCarMoreDetail.OtherAccessories = myDataTable.Rows[0]["OtherAccessories"].ToString();
            myCarMoreDetail.HasVechicleModified = Convert.ToBoolean(myDataTable.Rows[0]["HasVechicleModified"].ToString());
            myCarMoreDetail.VechicleModifyReason = myDataTable.Rows[0]["VechicleModifyReason"].ToString();
            myCarMoreDetail.HasCOE = Convert.ToBoolean(myDataTable.Rows[0]["HasCOE"].ToString());
            myCarMoreDetail.CarRentalExten = Convert.ToBoolean(myDataTable.Rows[0]["CarRentalExten"].ToString());
            myCarMoreDetail.NCDProtectorExten = Convert.ToBoolean(myDataTable.Rows[0]["NCDProtectorExten"].ToString());
            myCarMoreDetail.DealerWorkShopExten = Convert.ToBoolean(myDataTable.Rows[0]["DealerWorkShopExten"].ToString());
            myCarMoreDetail.SunRoofExten = Convert.ToBoolean(myDataTable.Rows[0]["SunRoofExten"].ToString());
            myCarMoreDetail.SunRoofAmount = Convert.ToSingle(myDataTable.Rows[0]["SunRoofAmount"].ToString());
            myCarMoreDetail.MoonRoofExten = Convert.ToBoolean(myDataTable.Rows[0]["MoonRoofExten"].ToString());
            myCarMoreDetail.MoonRoofAmount = Convert.ToSingle(myDataTable.Rows[0]["MoonRoofAmount"].ToString());
            myCarMoreDetail.OtherExtension = myDataTable.Rows[0]["OtherExtension"].ToString();
            myCarMoreDetail.SocialUse = Convert.ToBoolean(myDataTable.Rows[0]["SocialUse"].ToString());
            myCarMoreDetail.HasPhysicalImpairmty = Convert.ToBoolean(myDataTable.Rows[0]["HasPhysicalImpairmty"].ToString());
            myCarMoreDetail.PhysicalImpairmtyReason = myDataTable.Rows[0]["PhysicalImpairmtyReason"].ToString();
            myCarMoreDetail.HasAccidentInvolved = Convert.ToBoolean(myDataTable.Rows[0]["HasAccidentInvolved"].ToString());
            myCarMoreDetail.AccidentInvolvedReason = myDataTable.Rows[0]["AccidentInvolvedReason"].ToString();
            myCarMoreDetail.HasTrafficConvicted = Convert.ToBoolean(myDataTable.Rows[0]["HasTrafficConvicted"].ToString());
            myCarMoreDetail.TrafficConvictedReason = myDataTable.Rows[0]["TrafficConvictedReason"].ToString();
            myCarMoreDetail.HasInsuranceTerminated = Convert.ToBoolean(myDataTable.Rows[0]["HasInsuranceTerminated"].ToString());
            myCarMoreDetail.InsuranceTerminatedReason = myDataTable.Rows[0]["InsuranceTerminatedReason"].ToString();
            myCarMoreDetail.HasDemeritPoints = Convert.ToBoolean(myDataTable.Rows[0]["HasDemeritPoints"].ToString());
            myCarMoreDetail.HasPreInsurer = Convert.ToBoolean(myDataTable.Rows[0]["HasPreInsurer"].ToString());
            myCarMoreDetail.PreInsurerName = myDataTable.Rows[0]["PreInsurerName"].ToString();
            myCarMoreDetail.PreInsVechicleNo = myDataTable.Rows[0]["PreInsVechicleNo"].ToString();
            myCarMoreDetail.PreInsNCD = Convert.ToInt32(myDataTable.Rows[0]["PreInsNCD"].ToString());
            myCarMoreDetail.PreInsPolicyNo = myDataTable.Rows[0]["PreInsPolicyNo"].ToString();
            myCarMoreDetail.PreInsExpiryDate = Convert.ToDateTime(myDataTable.Rows[0]["PreInsExpiryDate"].ToString());
            myCarMoreDetail.RowGUID = myDataTable.Rows[0]["RowGUID"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());

            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

    }
}